import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: '资方产品/利率/政策',
    dataIndex: 'customerPath',
    width: 110,
    align: "left",
    customRender: ({ text, record }) => {
      if (record.type != '2') {
        return text;
      } else {
        return render.renderTag(text, 'red');
      }
    },
    ellipsis:true
  },
  { 
    title: '期数',
    dataIndex: 'timeLimit',
    width: 26,
    // customRender: ({ text }) => {
    //   return render.renderDict(text, 'periods');
    // },
  },
  {
    title: '月息',
    dataIndex: 'monthPer',
    width: 25,
  },
  {
    title: '基础奖励',
    dataIndex: 'baseRewards',
    width: 37,
    customRender: ({ text }) => text == '0.00%' ? text : render.renderColor(text, "text-red-500")
  },
  {
    title: '季度奖励',
    dataIndex: 'quarterlyRewards',
    width: 37,
    customRender: ({ text }) => text == '0.00%' ? text : render.renderColor(text, "text-red-500")
  },
  {
    title: '达标奖励',
    dataIndex: 'kpiRewards',
    width: 37,
    customRender: ({ text }) => text == '0.00%' ? text : render.renderColor(text, "text-red-500")
  },
  {
    title: '促销奖励',
    dataIndex: 'marketingRewards',
    width: 37,
    customRender: ({ text }) => text == '0.00%' ? text : render.renderColor(text, "text-red-500")
  },
  {
    title: '风险奖励',
    dataIndex: 'controlRewards',
    width: 37,
    customRender: ({ text }) => text == '0.00%' ? text : render.renderColor(text, "text-red-500")
  },
  {
    title: '税率',
    dataIndex: 'taxRatio',
    width: 35,
    customRender: ({ text }) => text == '0.00%' ? text : render.renderColor(text, "text-red-500")
  },
  {
    title: '奖励合计',
    dataIndex: 'totalRewards',
    width: 37,
    customRender: ({ text }) => text == '0.00%' ? text : render.renderColor(text, "text-red-500")
  },
  {
    title: 'GPS',
    dataIndex: 'gps',
    width: 35,
    customRender: ({ text }) => render.renderColor(text, "text-red-500")
  },
  {
    title: '其他费用',
    dataIndex: 'amountOther',
    width: 37,
  },
  {
    title: '有效日期',
    dataIndex: 'effectSdate',
    width: 95,
  },
  {
    title: '操作人',
    dataIndex: 'updateName',
    width: 40,
  },
  {
    title: '操作时间',
    dataIndex: 'updateTime',
    width: 60,
    format: 'date|YYYY-MM-DD'
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '资方',
    field: 'capitalName',
    component: 'Input',
    componentProps: {
      placeholder: ''
    }
  },
  {
    label: '产品',
    field: 'productName',
    component: 'Input',
    componentProps: {
      placeholder: ''
    }
  },
];

export const columnsSel: BasicColumn[] = [
  {
    title: '资方',
    dataIndex: 'capitalName',
    width: 55,
  },
  {
    title: '产品',
    dataIndex: 'productName',
    width: 55,
  },
  {
    title: '等级',
    dataIndex: 'customerLevel',
    width: 30,
    customRender: ({ text }) => {
      return text ? text : '-';
    },
  },
  { 
    title: '期数',
    dataIndex: 'timeLimit',
    width: 35,
    customRender: ({ text }) => {
      return render.renderDict(text, 'periods');
    },
  },
  {
    title: '利率',
    dataIndex: 'rate',
    width: 40,
  },
  {
    title: '月息',
    dataIndex: 'monthPer',
    width: 40,
  },
  {
    title: '奖励合计',
    dataIndex: 'totalRewards',
    width: 45,
  },
  {
    title: 'GPS',
    dataIndex: 'gps',
    width: 45,
  },
  {
    title: '其他费用',
    dataIndex: 'amountOther',
    width: 45,
  },
  
];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  { label: '', field: 'productCode', component: 'Input', show: false },
  { label: "", field: "customerId", component: "Input", show: false },
  {
    label: '政策类型',
    field: 'policyType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'policyType@ddlxUser',
      placeholder: ' ',
      getPopupContainer: () => document.body,
    },
    colProps: { span: 11 },
    rules: [{required: true,  message: '不能为空！'}],
  },
  {
    label: '资方产品',
    field: 'cId',
    component: 'Cascader',
    componentProps: {
      getPopupContainer: () => document.body,
    },
    dynamicRules: ({ model }) => {
      return [
        { required: true, message: '资方产品不能为空！' },
        { validator: (_, value) => {
            return new Promise((resolve, reject) => {
              if (!value) {
                return resolve() //不与required重复
              }
              let len = value.length;
              if ( len > 1) {
                model.customerId = value[len - 1]
                //console.info("dynamicRules", value, value[len - 1], model.customerId)
                return resolve()
              } else {
                model.customerId = ''
                return reject('选择的资方产品不对，请重新选择！');
              }
            });
          },
        },
      ]
    },
    colProps: {
      span: 11,
    },
  },
  {
    label: '期数',
    field: 'timeLimit',
    component: 'JDictSelectTag',
    colProps: { span: 11 },
    componentProps: {
      dictCode: 'periods',
      placeholder: ' ',
      stringToNumber: true,
      getPopupContainer: () => document.body,
    },
    rules: [{required: true,  message: '不能为空！'}],
  },
  {
    label: '利率',
    field: 'rate',
    component: 'InputNumber',
    colProps: { span: 11 },
    rules: [{required: true,  message: '不能为空！'}],
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
      //formatter: (value: number) => (value * 100).toFixed(2),
      //parser: (value: number) => (value / 100),
    },
  },
  {
    label: '月息',
    field: 'monthPer',
    component: 'Input',
    componentProps: {
      addonAfter: "厘"
    },
    colProps: { span: 11 },
  },
  {
    label: '系数',
    field: 'ratio',
    component: 'InputNumber',
    colProps: { span: 11 },
    componentProps: {
      min: "0",
    },
  },
  {
    label: '基础奖励',
    field: 'baseRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
      //formatter: (value: number) => (value * 100).toFixed(2),
      //parser: (value: number) => (value / 100),
    },
  },
  {
    label: '季度奖励',
    field: 'quarterlyRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
      //formatter: (value: number) => (value * 100).toFixed(2),
      //parser: (value: number) => (value / 100),
    },
  },
  {
    label: '促销奖励',
    field: 'marketingRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
      //formatter: (value: number) => (value * 100).toFixed(2),
      //parser: (value: number) => (value / 100),
    },
  },
  {
    label: '达标奖励',
    field: 'kpiRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
      //formatter: (value: number) => (value * 100).toFixed(2),
      //parser: (value: number) => (value / 100),
    },
  },
  {
    label: '风险奖励',
    field: 'controlRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
      //formatter: (value: number) => (value * 100).toFixed(2),
      //parser: (value: number) => (value / 100),
    },
  },
  {
    label: '奖励合计',
    field: 'totalRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
      //formatter: (value: number) => (value * 100).toFixed(2),
      //parser: (value: number) => (value / 100),
    },
  },
  {
    label: 'GPS',
    field: 'gps',
    component: 'InputNumber',
    colProps: { span: 11 },
  },
  {
    label: '其他费用',
    field: 'amountOther',
    component: 'InputNumber',
    colProps: { span: 11 },
  },
  {
    label: '其他费用',
    field: 'amountOther',
    component: 'InputNumber',
    colProps: { span: 11 },
  },
  {
    label: '生效开始时间',
    field: 'effectSdate',
    component: 'DatePicker',
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
    show: false
  },
  {
    label: '生效结束时间',
    field: 'effectEdate',
    component: 'DatePicker',
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
    show: false
  },
  {
    label: '生效日期',
    field: 'effectDate',
    component: 'RangePicker',
    required: true,
    componentProps: {
      valueType: 'Date',
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
  },
  {
    label: '税率',
    field: 'taxRatio',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
    },
  },
];

/**
 * 批量更新放款政策
 */
export const formBatch: FormSchema[] = [
  {
    label: '匹配参数',
    field: 'Divider1',
    component: 'Divider',
    colProps: { span: 24 },
  },
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  { label: '', field: 'productCode', component: 'Input', show: false },
  { label: "", field: "customerId", component: "Input", show: false },
  {
    label: '生效日期',
    field: 'effectDate1',
    component: 'RangePicker',
    required: true,
    componentProps: {
      valueType: 'Date',
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
    dynamicDisabled: true
  },
  {
    label: '资方产品',
    field: 'cId',
    component: 'Cascader',
    componentProps: {
      getPopupContainer: () => document.body,
    },
    dynamicRules: ({ model }) => {
      return [
        { required: true, message: '资方产品不能为空！' },
      ]
    },
    colProps: {
      span: 11,
    },
    dynamicDisabled: true
  },
  {
    label: '期数',
    field: 'timeLimit',
    component: 'JDictSelectTag',
    colProps: { span: 11 },
    componentProps: {
      dictCode: 'periods',
      placeholder: ' ',
      stringToNumber: true,
      getPopupContainer: () => document.body,
    },
    dynamicDisabled: true
  },
  {
    label: '利率',
    field: 'rate',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: '',
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
      placeholder: ' ',
      formatter: (value: number) => (value * 100).toFixed(2),
      parser: (value: number) => (value / 100),
    },
    dynamicDisabled: true
  },
  {
    label: '政策类型',
    field: 'policyType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'policyType@ddlxUser',
      placeholder: ' ',
      getPopupContainer: () => document.body,
      StringToNumber:true
    },
    colProps: { span: 11 },
  },
  {
    label: '更新参数',
    field: 'Divider2',
    component: 'Divider',
    colProps: { span: 24 },
  },
  {
    label: '基础奖励',
    field: 'baseRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
    },
  },
  {
    label: '季度奖励',
    field: 'quarterlyRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
    },
  },
  {
    label: '促销奖励',
    field: 'marketingRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
    },
  },
  {
    label: '达标奖励',
    field: 'kpiRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
    },
  },
  {
    label: '风险奖励',
    field: 'controlRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
    },
  },
  {
    label: '奖励合计',
    field: 'totalRewards',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
    },
  },
  {
    label: '生效日期',
    field: 'effectDate2',
    component: 'RangePicker',
    componentProps: {
      valueType: 'Date',
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
  },
  {
    label: '税率',
    field: 'taxRatio',
    component: 'InputNumber',
    colProps: { span: 11 },
    defaultValue: 0.0,
    componentProps: {
      step: "0.1",
      max: "20",
      addonAfter: "%",
    },
  },
  {
    label: 'GPS',
    field: 'gps',
    component: 'InputNumber',
    colProps: { span: 11 },
    componentProps: {
      placeholder: ' ',
    },
  },
  {
    label: '其他费用',
    field: 'amountOther',
    component: 'InputNumber',
    colProps: { span: 11 },
    componentProps: {
      placeholder: ' ',
    },
  },
  {
    label: '生效开始时间',
    field: 'beginDate',
    component: 'Input',
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
    show: false
  },
  {
    label: '生效结束时间',
    field: 'endDate',
    component: 'Input',
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
    show: false
  },
  {
    label: '生效开始时间',
    field: 'effectSdate',
    component: 'Input',
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
    show: false
  },
  {
    label: '生效结束时间',
    field: 'effectEdate',
    component: 'Input',
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 11 },
    show: false
  },
];